<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
${r'<%@'} include file="/view/common/include.jsp" ${r'%>'}
${r'<%@'} include file="/view/common/FormValid.jsp" ${r'%>'}
<title>新增</title>

<script type="text/javascript">
	var optName = ${r'"${'}param.optName${r'}"'};
	$(function() {
		// 数据验证
		validate();

		/*装载修改时的数据*/
 		initData();
		
		/*绑定关闭*/
		$('.l-button-colse').click(function() {
			windowClose();
		});
		
	});
	
	/**
	 * 表单提交
	 */
	function validate() {
		/*  表单提交 **/
		$("#dataForm").validate({
			rules: {
			<#list columns as column>
			<#if column.isPk != true>
			  <#if column_has_next>
				${column.column_name}	:	{<#if column.is_nullable == "NO">required:true,</#if>maxlength:${column.char_octet_length}},
			  <#else>
				${column.column_name}	:	{<#if column.is_nullable == "NO">required:true,</#if>maxlength:${column.char_octet_length}}
			  </#if>
			 </#if>
			</#list>				
			},
			submitHandler: function(form) {
	        	$("#dataForm").ajaxSubmit({
	            	beforeSubmit:function(formData, jqForm, options){
		    			return true; 
					},
		            success	:function(msg){
		                if(msg.flag){
		                	parent.searchGrid();
		                	windowClose();
						}else{
							$.messager.alert("提示", msg.desc, 'error');
	  					}
		           	},
		            url :  CP + '${actionVisitLocation}/save.htm?r=' + Math.random() + '&optName=${r'${param.optName}'}',
		            type :  "post",dataType:"json"
				});
			}
		});
		
	}

	function initData() {
		if (optName == 'edit' || optName == 'search') {
			var data = ${r'${'}datamap == null ? "\'\'":datamap};
			$('#dataForm').form('load',data);			
	<#list columns as column>
		//	$('#${column.column_name}').val(data.${column.column_name});
	</#list>			
		}
		if(optName == 'edit' || optName == 'add'){
			$("#formSubmit").css("display", "block");
			$('input,select,textarea', $('#dataForm')).removeAttr('readonly');
			$("input:not(:button),select,textarea").removeAttr("disabled");			
		}		
	}
	
	function windowClose(){
		parent.window.$('#easy-win').window("close");
	}
	
	function formSubmit(){
		$('#dataForm').form('submit');
	}
</script>

</head>
<body style="padding: 6px;">

<form id="dataForm">
	<!-- 隐藏域值 -->
	<input type="hidden" id="${table.pks[0].column_name}"  name="${table.pks[0].column_name}" />
			<!--表单域值	-->
	<div class="l-form">
		<div class="l-form-container">
			<ul>
	<#list columns as column>
		<#if column.isPk != true>
				<li class="l-fieldcontainer" name="${column.column_name}">
					<ul>
						<li class="li_label"><label><#if column.is_nullable == "NO"><font color="red">*</font></#if>${column.remarks}</label></li>
						<li class="li_input">
					<#if (column.char_octet_length > 200)>
							<textarea name="${column.column_name}" id="${column.column_name}" style="width:510px;height:97px;" placeholder="${column.remarks}"  disabled="disabled" readonly="readonly"></textarea>
					<#else>
							<input name="${column.column_name}" id="${column.column_name}"  type="text" placeholder="${column.remarks}" lay-verify="" autocomplete="off" data-options="" disabled="disabled" readonly="readonly"/>
					</#if>						
						</li>
					</ul>
				</li>		
		</#if>
	</#list>
			</ul>
		</div>
	</div>
	<!--表单动作按钮	-->
	<div align="center">
		<button id="formSubmit" type="submit" class="btn btn-primary btn-sm " style="margin-right: 100px;">提交</button>
		<button  type="button" class="btn btn-primary btn-sm l-button-colse">关闭</button>
	</div>
</form>
</body>
</html>